package yeliuhuishi.hadoopSerialization;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/**
 * key:
 * 13897230503
 * value:
 * < upFlow:400, dFlow:1300, sumFlow:1700 >,
 * < upFlow:100, dFlow:300, sumFlow:400 >
 * 迭代bean对象集合，累加各项，形成一个新的bean对象，例如：
 * < upFlow:400+100, dFlow:1300+300, sumFlow:1700+400 >
 * 最后输出：
 * key: 13897230503
 * value: < upFlow:500, dFlow:1600, sumFlow:2100 >
 */
public class FlowBean implements Writable {

    private long upFlow;
    private long dFlow;
    private long sumFlow;

    public FlowBean() {
    }

    public FlowBean(long upFlow, long dFlow) {
        this.upFlow = upFlow;
        this.dFlow = dFlow;
        this.sumFlow = upFlow + dFlow;
    }


    public void write(DataOutput out) throws IOException {
        out.writeLong(upFlow);//wirte写入的顺序与read读取顺序
        out.writeLong(dFlow);
        out.writeLong(sumFlow);
    }


    public void readFields(DataInput in) throws IOException {
        upFlow = in.readLong();
        dFlow = in.readLong();
        sumFlow = in.readLong();
    }

    public long getUpFlow() {
        return upFlow;
    }

    public void setUpFlow(long upFlow) {
        this.upFlow = upFlow;
    }

    public long getdFlow() {
        return dFlow;
    }

    public void setdFlow(long dFlow) {
        this.dFlow = dFlow;
    }

    public long getSumFlow() {
        return sumFlow;
    }

    public void setSumFlow(long sumFlow) {
        this.sumFlow = sumFlow;
    }

    @Override
    public String toString() {
        return "FlowBean{" +
                "upFlow=" + upFlow +
                ", dFlow=" + dFlow +
                ", sumFlow=" + sumFlow +
                '}';
    }
}